package com.opc.controller;

import com.opc.service.DeviceRecordService;
import com.opc.utils.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 作者
 * @since 2023-03-13
 */
@Slf4j
@RestController
@RequestMapping("/history")
@CrossOrigin("*")
public class HistoryController {

    @Autowired
    private DeviceRecordService recordService;

    @GetMapping("/abnormal_history")
    public ApiResult getAbnormalHistory(@RequestParam(name = "proLine", required = false) String proLine,
                                        @RequestParam(name = "startTime", required = false) String startTime,
                                        @RequestParam(name = "endTime", required = false) String endTime,
                                        @RequestParam(name = "valType", required = false, defaultValue = "2") String valType,
                                        @RequestParam(name = "recordType", required = false) String recordType,
                                        @RequestParam(name = "pageNo", required = false, defaultValue = "1") String pageNo,
                                        @RequestParam(name = "pageSize", required = false, defaultValue = "15") String pageSize) {
        return ApiResult.success(recordService.getAbnormalHistory(proLine, startTime, endTime, valType, recordType, Integer.parseInt(pageNo), Integer.parseInt(pageSize)));
    }

    @GetMapping("/history_list")
    public ApiResult getHistoryList(@RequestParam(name = "proLine", required = false) String proLine,
                                    @RequestParam(name = "startTime", required = false) String startTime,
                                    @RequestParam(name = "endTime", required = false) String endTime,
                                    @RequestParam(name = "valType", required = false, defaultValue = "2") String valType,
                                    @RequestParam(name = "recordType", required = false) String recordType,
                                    @RequestParam(name = "pageNo", required = false, defaultValue = "1") String pageNo,
                                    @RequestParam(name = "pageSize", required = false, defaultValue = "15") String pageSize) {
        return ApiResult.success(recordService.getHistoryList(proLine, startTime, endTime, valType, recordType, Integer.parseInt(pageNo), Integer.parseInt(pageSize)));
    }

    @PostMapping("/del/abnormal")
    public ApiResult delAbnormal(@RequestBody Map<String, Long[]> deviceIds) {
        return ApiResult.success(recordService.delAbnormal(deviceIds.get("deviceIds")));
    }


}
